//
//  PhotoBrowserCell.m
//  HorizontalAnimationDemo
//
//  Created by mysj on 16/7/6.
//  Copyright © 2016年 __defaultyuan. All rights reserved.
//

#import "PhotoBrowserCell.h"
#import "Masonry.h"
#import "PhotoBrowserLayoutAttributes.h"

@interface PhotoBrowserCell ()

@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UILabel *stitleLabel;
@property (nonatomic, strong) UILabel *dtitleLabel;
// 屏蔽层
@property (readwrite, nonatomic, strong) CALayer *shieldLayer;

@end

@implementation PhotoBrowserCell

- (void)applyLayoutAttributes:(UICollectionViewLayoutAttributes *)layoutAttributes {
    [super applyLayoutAttributes:layoutAttributes];
    
     
    PhotoBrowserLayoutAttributes *theLayoutAttributes = (PhotoBrowserLayoutAttributes *)layoutAttributes;
    
    self.shieldLayer.opacity = (float)theLayoutAttributes.shieldAlpha;
}


- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        
        [self prepareView];
    }
    return self;
}


- (void)prepareView {

    [self.contentView addSubview:self.imageView];
    [self.contentView addSubview:self.titleLabel];
    [self.contentView addSubview:self.stitleLabel];
    [self.contentView addSubview:self.dtitleLabel];
 
    [self.layer addSublayer:self.shieldLayer];
    
    

    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.contentView).offset(2);
        make.top.equalTo(self.contentView);
    }];
    
    [self.stitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView);
        make.bottom.equalTo(self.contentView).offset(2);
    }];
    
    [self.dtitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.contentView);
        make.bottom.equalTo(self.contentView).offset(2);
    }];
    
     [self.imageView mas_makeConstraints:^(MASConstraintMaker *make) {
         make.left.equalTo(self.contentView);
         make.right.equalTo(self.contentView);
         make.top.equalTo(self.contentView).offset(15.5);
         make.bottom.equalTo(self.stitleLabel.mas_top).offset(-5);
     }];
    
}

#pragma mark -
- (CALayer *)shieldLayer {
    
    if (!_shieldLayer) {
        _shieldLayer = [CALayer layer];
        _shieldLayer.frame = self.bounds;
//        _shieldLayer.backgroundColor = [UIColor whiteColor].CGColor;
        _shieldLayer.zPosition = FLT_MAX;
    }
    return _shieldLayer;
}

- (UILabel *)dtitleLabel {

    if (!_dtitleLabel) {
        _dtitleLabel = [[UILabel alloc] init];
        _dtitleLabel.text = @"【 29 】";
        _dtitleLabel.textColor = [UIColor colorWithRed:166/255.0 green:248/255.0 blue:1 alpha:1.0];
        _dtitleLabel.font = [UIFont systemFontOfSize:12];
        [_dtitleLabel sizeToFit];
    }
    return _dtitleLabel;
}

- (UILabel *)stitleLabel {
    if (!_stitleLabel) {
        _stitleLabel = [[UILabel alloc] init];
        _stitleLabel.text = @"35米";
        _stitleLabel.textColor = [UIColor redColor];
        _stitleLabel.font = [UIFont systemFontOfSize:12];
        _stitleLabel.textColor = [UIColor colorWithRed:166/255.0 green:248/255.0 blue:1 alpha:1.0];
        [_stitleLabel sizeToFit];
    }
    return _stitleLabel;
}

- (UILabel *)titleLabel {
    if (!_titleLabel) {
        _titleLabel = [[UILabel alloc] init];
        _titleLabel.text = @"L4";
        _titleLabel.textColor = [UIColor redColor];
        _titleLabel.font = [UIFont systemFontOfSize:12];
        [_titleLabel sizeToFit];
    }
    return _titleLabel;
}

- (UIImageView *)imageView {

    if (!_imageView) {
        _imageView = [[UIImageView alloc] init];
        _imageView.contentMode = UIViewContentModeScaleToFill;
    }
    return _imageView;
}

@end
